   /**
  ******************************************************************************
  * @file    Project/STM32F10x_StdPeriph_Template/stm32f10x_it.c 
  * @author  MCD Application Team
  * @version V3.5.0
  * @date    08-April-2011
  * @brief   Main Interrupt Service Routines.
  *          This file provides template for all exceptions handler and 
  *          peripherals interrupt service routine.
  ******************************************************************************
  * @attention
  *
  * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  *
  * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
  ******************************************************************************
  */

/* Includes ------------------------------------------------------------------*/
#include "stm32f10x_it.h"
#include "device.h"
#include "system.h"



/** @addtogroup STM32F10x_StdPeriph_Template
  * @{
  */

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/

/******************************************************************************/
/*            Cortex-M3 Processor Exceptions Handlers                         */
/******************************************************************************/

/**
  * @brief  This function handles NMI exception.
  * @param  None
  * @retval None
  */
void NMI_Handler(void)
{
}

/**
  * @brief  This function handles Hard Fault exception.
  * @param  None
  * @retval None
  */
void HardFault_Handler(void)
{
  /* Go to infinite loop when Hard Fault exception occurs */
  while (1)
  {
  }
}

/**
  * @brief  This function handles Memory Manage exception.
  * @param  None
  * @retval None
  */
void MemManage_Handler(void)
{
  /* Go to infinite loop when Memory Manage exception occurs */
  while (1)
  {
  }
}

/**
  * @brief  This function handles Bus Fault exception.
  * @param  None
  * @retval None
  */
void BusFault_Handler(void)
{
  /* Go to infinite loop when Bus Fault exception occurs */
  while (1)
  {
  }
}

/**
  * @brief  This function handles Usage Fault exception.
  * @param  None
  * @retval None
  */
void UsageFault_Handler(void)
{
  /* Go to infinite loop when Usage Fault exception occurs */
  while (1)
  {
  }
}

/**
  * @brief  This function handles SVCall exception.
  * @param  None
  * @retval None
  */
void SVC_Handler(void)
{
}

/**
  * @brief  This function handles Debug Monitor exception.
  * @param  None
  * @retval None
  */
void DebugMon_Handler(void)
{
}

/**
  * @brief  This function handles PendSVC exception.
  * @param  None
  * @retval None
  */
 #if 0 
void PendSV_Handler(void)
{
}
 #endif

static void dummy(void)
{
}

#define SystemTick10000Sum 2
#define SystemTick1000Sum  4
#define SystemTick100Sum   8

function SystemTick10000Block[SystemTick10000Sum] = {dummy, dummy};
function SystemTick1000Block[SystemTick1000Sum] = {dummy, dummy, dummy, dummy};
function SystemTick100Block[SystemTick100Sum] = {dummy, dummy, dummy, dummy, dummy, dummy, dummy, dummy};



static bool SystemTickRegister(SystemTick systemTick, function callbackFucntion)
{
    static byte SystemTick100Counter = 0;
    static byte SystemTick1000Counter = 0;
    static byte SystemTick10000Counter = 0;

    Assert(callbackFucntion != (function)0);
    EnterCritical();
    switch(systemTick)
    {
        case SystemTick100:
            if (SystemTick100Counter == SystemTick100Sum)
                return(false);
            
            SystemTick100Block[SystemTick100Counter++] = callbackFucntion;  
            ExitCritical();
            return(true);
        case SystemTick1000:
            if (SystemTick1000Counter == SystemTick1000Sum)
                return(false);
            
            SystemTick1000Block[SystemTick1000Counter++] = callbackFucntion;   
            ExitCritical();
            return(true);
        case SystemTick10000:
            if (SystemTick10000Counter == SystemTick10000Sum)
                return(false);
            
            SystemTick10000Block[SystemTick10000Counter++] = callbackFucntion;   
            ExitCritical();
            return(true);
        default:
            ExitCritical();
            return(false);
    }
}

void InitializeSystemTick(void)
{
    System.Device.SystemTick.Register = SystemTickRegister;
    SysTick_Config(SystemCoreClock / 10000);
}

/**
  * @brief  This function handles SysTick Handler.
  * @param  None
  * @retval None
  */
void SysTick_Handler(void)
{
    static unsigned char Counter = 0;
	
    if(++Counter == 100)
    {
        Counter = 0;
    }

    SystemTick10000Block[0]();
    SystemTick10000Block[1]();

    switch(Counter) 
    {
        case 0:
        case 10:
        case 20:
        case 30:
        case 40:
        case 50:
        case 60:
        case 70:
        case 80:
        case 90:
            SystemTick1000Block[0]();
            break;
        case 2:
        case 12:
        case 22:
        case 32:
        case 42:
        case 52:
        case 62:
        case 72:
        case 82:
        case 92:
            SystemTick1000Block[1]();
            break;
        case 4:
        case 14:
        case 24:
        case 34:
        case 44:
        case 54:
        case 64:
        case 74:
        case 84:
        case 94:
            SystemTick1000Block[2]();
            break;
        case 6:
        case 16:
        case 26:
        case 36:
        case 46:
        case 56:
        case 66:
        case 76:
        case 86:
        case 96:
            SystemTick1000Block[3]();
            break;
        case 8:
        case 18:
        case 28:
        case 38:
        case 48:
        case 58:
        case 68:
        case 78:
        case 88:
        case 98:
            TraceSystemTickService();
            TimerSystemTickService();
            break;

        case 1:
            SystemTick100Block[0]();
            break;
        case 3:
            SystemTick100Block[1]();
			break;
        case 5:
            SystemTick100Block[2]();
            break;
        case 7:
            SystemTick100Block[3]();
            break;
        case 9:
            SystemTick100Block[4]();
            break;
        case 11:
            SystemTick100Block[5]();
            break;
        case 13:
            SystemTick100Block[6]();
            break;
        case 15:
            SystemTick100Block[7]();
            break;  
            
        case 97:
            RtcSystemTickService();
            break;
        case 99:
            KeySystemTickService();
            break; 
        default:
            break;
    }
}

/******************************************************************************/
/*                 STM32F10x Peripherals Interrupt Handlers                   */
/*  Add here the Interrupt Handler for the used peripheral(s) (PPP), for the  */
/*  available peripheral interrupt handler's name please refer to the startup */
/*  file (startup_stm32f10x_xx.s).                                            */
/******************************************************************************/

/**
  * @brief  This function handles PPP interrupt request.
  * @param  None
  * @retval None
  */
/*void PPP_IRQHandler(void)
{
}*/

/**
  * @}
  */ 


/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
